$(function () {
  //显示登录弹窗
  $(".user-login.text-link").on("click", function (ev) {
    let mask = `<div class="quc-mask"></div>`;
    let userLogin = `
  <div class="quc-panel">
    <div class="quc-panel-hd">
      <div class="quc-panel-title">
        <div>
          <div class="quc-panel-list">
            <div class="codelogin">短信登录</div>
            <span>丨</span>
            <div class="userlogin active">360账号登录</div>
          </div>
        </div>
      </div>
      <a href="" class="quc-panel-close">
        <i class="iconfont icon-close"></i>
      </a>
    </div>
    <div class="quc-panel-bd">
      <div class="quc-main">
        <div>
          <form action="" method="post" class="quc-form">
          <div class="quc-form-item">
          <div class="quc-input">
            <input type="text" placeholder="手机号/用户名/邮箱" />
          </div>
        </div>
        <div class="quc-form-item">
          <div class="quc-input">
            <input type="password" placeholder="密码" />
          </div>
        </div>
            <div class="quc-button-list">
              <input type="button" value="登录" class="quc-button-primary" />
            </div>
            <div class="quc-form-tips">
              <a href="" class="tips tips-left">快速注册</a>
              <a href="" class="tips tips-right">找回密码</a>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
  `;

    let phoneLogin = `
  <div class="quc-panel">
    <div class="quc-panel-hd">
      <div class="quc-panel-title">
        <div>
          <div class="quc-panel-list">
            <div class="codelogin active">短信登录</div>
            <span>丨</span>
            <div class="userlogin">360账号登录</div>
          </div>
        </div>
      </div>
      <a href="" class="quc-panel-close">
        <i class="iconfont icon-close"></i>
      </a>
    </div>
    <div class="quc-panel-bd">
      <div class="quc-main">
        <div>
          <form action="" method="post" class="quc-form">
          <div class="quc-form-item">
          <div class="quc-input">
            <input type="text" placeholder="手机号" />
          </div>
          <div class="quc-input-err">请输入手机号</div>
          </div>
          <div class="quc-form-item">
          <div class="quc-input">
            <input type="text" placeholder="短信验证码" />
            <div class="quc-input-append">
              <span>获取验证码</span>
            </div>
          </div>
          </div>
            <div class="quc-button-list">
              <input type="button" value="登录" class="quc-button-primary" />
            </div>
            <div class="quc-form-tips">
              <a href="" class="tips tips-left">快速注册</a>
              <a href="" class="tips tips-right">找回密码</a>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
  `;

    $("body").append(mask);
    $("body").append(phoneLogin);
    $("body").on("click", function (ev) {
      if ($(ev.target).is($(".codelogin"))) {
        $(".quc-panel").replaceWith(phoneLogin);
      } else if ($(ev.target).is($(".userlogin"))) {
        $(".quc-panel").replaceWith(userLogin);
      } else if ($(ev.target).is($("i.iconfont.icon-close"))) {
        $(".quc-mask").remove();
        $(".quc-panel").remove();
      }
    });
  });

  $(".cart").on("mouseenter", function (ev) {
    if ($(ev.currentTarget).is($("div.cart"))) {
      $(".cart-detail-box").css("display", "block");
    }
  });
  $(".cart").on("mouseleave", function (ev) {
    if ($(ev.currentTarget).is($("div.cart"))) {
      $(".cart-detail-box").css("display", "none");
    }
  });

  //楼梯特效
  $(".index-elevator-box>.elevator-item").on("click", function () {
    let id = $(this).attr("data-index");
    let elm = $(".floor").get(id);
    let top = $(elm).offset().top - 70;
    $("html").animate(
      {
        scrollTop: top,
      },
      0
    );
  });
  $(window).on("scroll", function (ev) {
    // console.log($(document).scrollTop());
    let top = $(document).scrollTop();
    let _index = Math.round((top - 550) / 1000);
    //显示隐藏左边菜单
    if (top >= 600) {
      $(".index-elevator-box").css("transform", "scale(1)");
    } else {
      $(".index-elevator-box").css("transform", "scale(0)");
    }

    $(".index-elevator-box>.elevator-item")
      .removeClass("active")
      .eq(_index)
      .addClass("active");
    if (top >= 8000) {
      $(".index-elevator-box>.elevator-item")
        .removeClass("active")
        .eq(7)
        .addClass("active");
    }

    //显示隐藏回到顶部
    if (top > 800) {
      $(".backtop").css("transform", "scaleY(1)");
    } else {
      $(".backtop").css("transform", "scaleY(0)");
    }
  });

  //回到顶部
  $(".backtop").on("click", function () {
    $("html").animate(
      {
        scrollTop: 0,
      },
      0
    );
  });

  //优惠券
  $(".js_coupon").on("click", function (ev) {
    if ($(".right-side").hasClass("open")) {
      $(".right-side").removeClass("open");
    } else {
      $(".right-side").addClass("open");
    }
  });
});
